package com.kzd.sdk.base;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.kzd.sdk.callback.KZD_OnClickListener;
import com.kzd.sdk.utils.AppUtils;

public abstract class OwnerFragment extends Fragment {

    private boolean isFirstLoad = false;

    public Context mContext;

    public KZD_OnClickListener mOnClickListener;

    public void setOnClickListener(KZD_OnClickListener onClickListener){
        this.mOnClickListener = onClickListener;
    }

    public abstract String getLayoutIdByName();

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        this.mContext = context;
    }

    //    @Override
//    public void onAttach(Context context) {
//        super.onAttach(context);
//        this.mContext = context;
//    }
//
//    @Override
//    public void onAttach(Activity activity) {
//        super.onAttach(activity);
//        this.mActivity = activity;
//    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(AppUtils.getLayoutId(mContext, getLayoutIdByName()), container, (false));
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    @Override
    public void onResume() {
        super.onResume();
        if (!isFirstLoad) {
            initData();
            isFirstLoad = true;
        } else {
            onRefreshLoad();
        }
    }

    public void initView(View view) {

    }

    public void initData() {

    }

    public void onRefreshLoad() {

    }

    public void toast(String text){
        Toast.makeText(mContext,text,Toast.LENGTH_SHORT).show();
    }
}
